<?PHP
class datacache
{

	private $primarykey;
	private $memcache;

	public function __construct($key)
	{
		global $scfg;
		if (empty ($key))
			return false;
		$this->primarykey= 'cm_' . $key;
		if (!$this->memcache)
		{
			$this->memcache= new Memcache;
			foreach($scfg["memcache"] as $v)			
				$this->memcache->addServer($v[0], $v[1], $v[2], $v[3]);
			$this->memcache->setCompressThreshold(20000, 0.2);
		}
	}

	public function get()
	{
		return $this->memcache->get($this->primarykey);
	}

	public function put($val, $expire= 1592000)
	{
		return $this->memcache->set($this->primarykey, $val, false, intval($expire));
	}

	public function del()
	{
		return $this->memcache->delete($this->primarykey);
	}

	public function status()
	{
		return $this->memcache->getExtendedStats();
	}

	public function __destruct()
	{
		if ($this->memcache)
		{
			$this->memcache->close();
		}
	}
}
?>